//
//  HorizontalBarMarker.swift
//  HuaYun
//
//  Created by enghou on 2018/10/9.
//  Copyright © 2018年 xyxorigation. All rights reserved.
//

import UIKit
import Charts
class HorizontalBarMarker: BarMarker {
    open override func refreshContent(entry: ChartDataEntry, highlight: Highlight)
    {
        
//        let month = self.chartView!.data!.dataSets[highlight.dataSetIndex].entryIndex(entry: entry)
//
//        let monthTitle = String(month + 1) + "月新增\n" + String(format: "%.2f", entry.y) + "万元"
        self.label = String(format: "%.2f", entry.y) + "万元"
//        setLabel(String(format: "%.2f", entry.y) + "万元")
        
    }
    
    open override func draw(context: CGContext, point: CGPoint)
    {
        guard let label = self.label else { return }
        
        let offset = self.offsetForDrawing(atPoint: point)
        
        var rect = CGRect(
            origin: CGPoint(
                x: point.x + offset.x,
                y: point.y + offset.y),
            size: size)
        
        rect.origin.x -= size.width / 2.0
        
        context.saveGState()
        
        context.setFillColor(color.cgColor)
        
        let path = CGMutablePath.init()
        
        path.addRoundedRect(in: rect, cornerWidth: 2, cornerHeight: 2)
        
        context.addPath(path)
        
        context.fillPath()
        
        UIGraphicsPushContext(context)
        
        label.draw(in: CGRect(x: rect.origin.x + insets.left * 1.4, y: rect.origin.y + insets.top * 1.4, width: _labelSize.width, height: _labelSize.height), withAttributes: _drawAttributes)
        
        UIGraphicsPopContext()
        
        context.restoreGState()
    }
}
